package com.geely.club.util.project;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.geely.club.R;

/**
 * Created by mengyangyang on 2015-10-15.
 */
public class DialogUtil {
    public static Dialog getConfirmDialog(String message, Activity context, final Runnable confirmRunnable, final Runnable cancelRunnable) {
        final Dialog dialog = new Dialog(context);
        dialog.setCancelable(true);
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_confirm);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        ((TextView) dialog.getWindow().findViewById(R.id.tv_title)).setText(message);
        dialog.getWindow().findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                confirmRunnable.run();
                dialog.dismiss();
            }
        });
        dialog.getWindow().findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancelRunnable.run();
                dialog.dismiss();
            }
        });
        return dialog;
    }
}
